﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using C2E2C.Repository;
using C2E2C.Web.ViewModels;
using C2E2C.Repository.Repositories;
using C2E2C.Entity;

namespace C2E2C.Web.Controllers
{
    public class UserController : C2E2CController
    {
        public UserController(
            IUnitOfWork unitOfWork, 
            IRepositoryContainer repositoryContainer)
            :base(unitOfWork, repositoryContainer)
        {
        }

        public IAccountRepository AccountRepository
        {
            get
            {
                return RepositoryContainer.Get<IAccountRepository>();
            }
        }

        public ActionResult Login(UserLoginModel model)
        {
            string username = model.UserName;
            string password = model.Password;
            var account = AccountRepository.Get(
                it => it.Email == username && it.Password == password);

            if (account == null)
            {
                return View();
            }
            else
            {
                return View("");
            }
        }

        [HttpGet]
        public ActionResult Register()
        {
            return View(new UserRegisterModel());
        }

        [HttpPost]
        public ActionResult Register(UserRegisterModel model)
        {
            var newAccount = new Account();
            if(TryUpdateModel(newAccount))
            {
                AccountRepository.Add(newAccount);
                UnitOfWork.Commit();
            }
            return View("JustRegister");
        }

        [HttpGet]
        public ActionResult ForgetPassword()
        {
            return PartialView();
        }

        [HttpPost]
        public ActionResult ForgetPassword(string email)
        {
            return PartialView();
        }
    }
}
